package cn.itsource.config;
import cn.itsource.config.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 */
@Configuration //声明是Mvc拦截器配置类
public class BlogMvcConfig implements WebMvcConfigurer {
//    注入拦截器依赖
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") //拦截所有路径,不分层级
                .excludePathPatterns("/login/**") //放行登录
                .excludePathPatterns("/html/**"); //放行登录

    }
}
